<?php
/**
 * Created by PhpStorm.
 * User: chindor
 * Date: 2017/6/14
 * Time: 11:11
 */

namespace app\api\modules\v1\knowledge\controllers;



use app\api\components\ApiController;
use app\api\modules\v1\knowledge\models\Question_z;
use app\api\modules\v1\market\models\Auth_z;
use app\api\modules\v1\market\models\Message;
use app\api\modules\v1\market\models\SessionMessage;

class DefaultController extends ApiController
{


    public function actionIndex()
    {

    }

    /**问题发布
     * @return array
     */
    public function actionPostQuestion()
    {
        $post = \yii::$app->request->post();

        //验证用户token
        if(!(new Auth_z()) -> auth($post)){
            return self::sendMessageJson(Message::AUTH_FAIL);
        }

        //发布问题
        if(!Question_z::post($post)){
            return self::sendMessageJson(SessionMessage::getMess());
        }

        return self::sendMessageJson(Message::OPERATE_SUCCESS,self::$CODE_SUC);

    }

    /**问题列表的获取
     * @return array
     */
    public function actionQuesitonList()
    {
        $get = \yii::$app->request->get();
        if(!$data = Question_z::quesiton_list()){
            return self::sendMessageJson(SessionMessage::getMess());
        }
        return self::sendMessageJson(Message::SUCCESS,self::$CODE_SUC,$data);
    }

    /**回答列表的获取
     * @return array
     */
    public function actionAnswerList()
    {
        if(!$data = Question_z::AnswerList(\yii::$app->request->get('question_id',null))){
            return self::sendMessageJson(SessionMessage::getMess());
        }
        return self::sendMessageJson(Message::SUCCESS,self::$CODE_SUC,$data);
    }

    /**回答问题
     * @return array
     */
    public function actionAnswerQuestion()
    {
        $post = \yii::$app->request->post();

        //验证用户token
        if(!(new Auth_z()) -> auth($post)){
            return self::sendMessageJson(Message::AUTH_FAIL);
        }

        //回答问题
        if(!Question_z::answer_question($post)){
            return self::sendMessageJson(SessionMessage::getMess());
        }

        return self::sendMessageJson(Message::OPERATE_SUCCESS,self::$CODE_SUC);
    }
}